//
//  TabViewAndNavigationView.swift
//  波形图demo
//
//  Created by apple on 2021/2/23.
//

import SwiftUI

struct TabViewAndNavigationView: View {
    var body: some View {
        TestNavigateTab()
    }
}

struct TestNavigateTab: View {
    var body: some View {
        VStack{
            NavigationView{
                VStack(alignment: .center, spacing: 0){
                    Spacer()
                    NavigationLink(
                        destination: AccueilView(selectedTab: 2)){
                        VStack(){
                            Image(systemName: "hare")
                            Text("兔子")
                        }
                    }
                    Spacer()
                    HStack(){
                        NavigationLink(
                            destination: AccueilView(selectedTab: 0)){
                            VStack(){
                                Image(systemName: "hare")
                                Text("兔子")
                            }
                        }
                    }
                    Spacer()
                }
            }
        }
    }
}

struct AccueilView: View {
    @State var selectedTab: Int
    
    init(selectedTab: Int) {
        _selectedTab = State(initialValue: selectedTab)
    }
    
    var body: some View {

        TabView(selection: $selectedTab) {
            Text("首页").tabItem {
                Image(systemName: "hare")
                Text("首页")
            }.tag(0)
            Text("产品").tabItem {
                Image(systemName: "hare")
                Text("产品")
            }.tag(1)
            Text("购物车").tabItem {
                Image(systemName: "hare")
                Text("购物车")
            }.tag(2)
            Text("我的").tabItem {
                Image(systemName: "hare")
                Text("我的")
            }.tag(3)
            Text("其他").tabItem {
                Image(systemName: "hare")
                Text("其他")
            }.tag(4)
        }
    }
}

struct TabViewAndNavigationView_Previews: PreviewProvider {
    static var previews: some View {
        TabViewAndNavigationView()
    }
}
